#include <QFocusEvent>

#include "searchbox.h"

SearchBox::SearchBox( QWidget * parent ) : QLineEdit( parent ) {
}

void SearchBox::focusInEvent( QFocusEvent * e ) {
    this->preserveText();
    this->clear();
}

void SearchBox::focusOutEvent( QFocusEvent * e ) {
    if ( this->text().isEmpty() ) {
        QLineEdit::setText( this->preservedText() );
    }
}

void SearchBox::setText( QString text ) {
    QLineEdit::setText( text );
    this->preserveText();
}

QString SearchBox::preservedText() {
    return this->mPreservedText;
}

void SearchBox::preserveText() {
    this->mPreservedText = this->text();
}
